package service

import (
	"context"
	"insighttracking/query/dao"
	"insighttracking/query/model"
)

type _purchasePlanOrdersService struct {
}

func (s _purchasePlanOrdersService) GetByOrdersDetailIdApi(ctx context.Context, item int64) (*model.PurchasePlanOrdersEntity, error) {
	return dao.PurchasePlanOrdersEntity.WithContext(ctx).Where(dao.PurchasePlanOrdersEntity.OrdersSpuID.Eq(item)).First()
}

func (s _purchasePlanOrdersService) GetByOrdersSpuIDApi(ctx context.Context, item int64) (*model.PurchasePlanOrdersEntity, error) {
	return dao.PurchasePlanOrdersEntity.WithContext(ctx).Where(dao.PurchasePlanOrdersEntity.OrdersSpuID.Eq(item)).First()
}

func (s _purchasePlanOrdersService) CreateApi(ctx context.Context, tx *dao.QueryTx, m *model.PurchasePlanOrdersEntity) error {
	if err := tx.PurchasePlanOrdersEntity.WithContext(ctx).Create(m); err != nil {
		return err
	}
	return nil
}

func (s _purchasePlanOrdersService) GetByOrdersDetailIdListApi(ctx context.Context, list []int64) ([]*model.PurchasePlanOrdersEntity, error) {
	return dao.PurchasePlanOrdersEntity.WithContext(ctx).Where(dao.PurchasePlanOrdersEntity.OrdersDetailsID.In(list...)).Find()
}

func (s _purchasePlanOrdersService) GetByOrdersDetailByPlanIdApi(ctx context.Context, id int64) ([]*model.PurchasePlanOrdersEntity, error) {
	return dao.PurchasePlanOrdersEntity.WithContext(ctx).Where(dao.PurchasePlanOrdersEntity.PurchasePlanID.Eq(id)).Find()
}

func (s _purchasePlanOrdersService) GetByOrdersDetailByPlanIdListApi(ctx context.Context, list []int64) ([]*model.PurchasePlanOrdersEntity, error) {
	return dao.PurchasePlanOrdersEntity.WithContext(ctx).Where(dao.PurchasePlanOrdersEntity.PurchasePlanID.In(list...)).Find()
}

var PurchasePlanOrdersService = new(_purchasePlanOrdersService)
